/*
 * Group.cpp
 *
 *  Created on: 19/05/2010
 *      Author: Nadav
 */

#include "Group.h"
#include <assert.h>
Group::Group(int objectsInGroup) {
	this->objectsInGroup = objectsInGroup;
	objects = new Object3D*[objectsInGroup];
}

Group::~Group() {
	for (int i=0; i<this->objectsInGroup; ++i) {
		delete objects[i];
	}
	delete[] objects;
}

bool Group::intersect(const Ray &r, Hit &h, float tmin) {
	bool intersects = false;
	for (int i=0; i<objectsInGroup; ++i) {
		if (objects[i]->intersect(r,h,tmin)) intersects = true;
	}
	return intersects;
}

void Group::addObject(int index, Object3D *obj) {
	assert(NULL != objects);
	assert(index>=0 && index<objectsInGroup);
	objects[index] = obj;
}
